<?php

namespace Portal\InvoiceBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Portal\UserBundle\Controller\LoginController;

class InvoiceComponentController extends Controller
{
    public function showInvoiceByComponentAction($invoiceId)
    {
      
      $user = LoginController::checkUser($this->container->get('security.context'));

      $invoice = $this->getDoctrine()->getEntityManager()->getRepository('PortalInvoiceBundle:Invoice')->findInvoiceById($invoiceId, $user->getId());
      if(!$invoice){
        $this->get('session')->setFlash('error', 'Энэ нэхэмжлэх байхгүй байна.');
        return $this->redirect($this->generateUrl('homepage'));
      }
      
      

      return $this->render('PortalInvoiceBundle:Component:showByComponent.html.twig', array(
          'invoice' => $invoice,
          
          ));
    }
}
